#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct tuple {
	int value;
	char name[12];
};

static void
merge_sort__merge(struct tuple *array, struct tuple * const sorted, int L, int M, int R)
{
	register int i = L,
		     j = M+1,
		     s = 0;

	while (i <= M && j <= R) {
		if (array[i].value <= array[j].value)
			sorted[s++] = array[i++];
		else
			sorted[s++] = array[j++];
	}
	while (i <= M)
		sorted[s++] = array[i++];
	while (j <= R)
		sorted[s++] = array[j++];

	i = 0;
	while (i < s) {
		array[L + i] = sorted[i];
		++i;
	}
}

static void
merge_sort__main(struct tuple *array, struct tuple * const sorted, int L, int R)
{
	int M;

	if (L < R) {
		M = (L + R) / 2;
		merge_sort__main(array, sorted, L, M);
		merge_sort__main(array, sorted, M + 1, R);
		merge_sort__merge(array, sorted, L, M, R);
	}
}

void
merge_sort_(struct tuple *array, int size)
{
	struct tuple *sorted;
	sorted = calloc((size_t) size, sizeof *sorted);
	merge_sort__main(array, sorted, 0, size - 1);
	free(sorted);
}

static int
ds(const char *s)
{
	int ans = 0;
	while (*s != '\0') {
		if (*s >= '0' && *s <= '9')
			ans += *s - '0';
		++s;
	}
	return ans;
}

int
main(int argc, char **argv)
{
	struct tuple *array;
	int n;
	register int i = 0;

	scanf("%d", &n);
	array = malloc(sizeof *array * (n + 1));
	for (i = 0; i < n; ++i) {
		scanf("%11s", array[i].name); /* yeah right, whoops */
		array[i].value = ds(array[i].name);
	}
	merge_sort_(array, n);
	for (i = 0 ; i < n ; ++i)
		printf("%s ", array[i].name);
	fputc('\n', stdout);

	free(array);
	return 0;
}
